package com.soft.bams.dao;

import com.soft.bams.entity.Account;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yzg
 * @desc TODO
 * @date 2025/4/23
 */
public class ListDao implements IDao<Account, List<Account>>{
    private List<Account> list;

    public ListDao() {
        list = new ArrayList<>();
    }

    //初始ID
    private Long id = 100000000000000000L;

    @Override
    public Long getId() {
        return this.id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public boolean insert(Account account) {
        list.add(account);
        return true;
    }

    @Override
    public Account selectOne(Long id, String password) {
        for (int i = 0; i < list.size(); i++) {
            Account acc = list.get(i);
            if (acc != null && acc.getId().equals(id) && acc.getPassword().equals(password)) {
                return acc;
            }
        }
        return null;
    }

    @Override
    public Account selectOne(Long id) {
        for (int i = 0; i < list.size(); i++) {
            Account acc = list.get(i);
            if (acc != null && acc.getId().equals(id)) {
                return acc;
            }
        }
        return null;
    }

    @Override
    public List<Account> selectAll() {
        return list;
    }

    @Override
    public boolean update(Account updatedAccount) {
        return false;
    }
}
